﻿# coding=utf-8
from django import forms
from django.db import models
from django.contrib.auth.models import User
from registration.forms import RegistrationForm
from datetime import date

conceitos = (('A', 'A'), ('B', 'B'), ('C', 'C'), ('D', 'D'), ('FF', 'FF'))
anos = range(1985, date.today().year + 1)

class Avaliacao(models.Model):
	professor = models.ForeignKey("Professor", related_name="avaliacoes")
	aluno = models.CharField(max_length=28) # hashing.
	disciplina = models.ForeignKey("Disciplina", related_name="avaliacoes")
	ano = models.IntegerField(max_length=4, choices=((ano, ano) for ano in anos))
	semestre = models.SmallIntegerField(max_length=1, choices=((1, 1), (2, 2)))
	nota_geral = models.CharField(max_length=2, choices=conceitos)
	cmnt_geral = models.TextField()
	nota_didatica = models.CharField(max_length=2, choices=conceitos)
	cmnt_didatica = models.TextField()
	nota_dinamica = models.CharField(max_length=2, choices=conceitos)
	cmnt_dinamica = models.TextField()
	nota_aval = models.CharField(max_length=2, choices=conceitos)
	cmnt_aval = models.TextField()
	nota_disp = models.CharField(max_length=2, choices=conceitos)
	cmnt_disp = models.TextField()
	resposta = models.TextField(blank=True, default="")
	karma = models.IntegerField(default=0)
	
	def __unicode__(self):
		return "%s - %s" % (self.disciplina.codigo, self.aluno)

class Professor(models.Model):
	usuario = models.ForeignKey(User, blank=True, null=True, default="", related_name="professor")
	username = models.CharField(max_length=20)
	nome = models.CharField(max_length=256) # vai que, sei lá, o Márcio vire professor...
	
	def __unicode__(self):
		return self.nome

class Disciplina(models.Model):
	codigo = models.CharField(max_length=8, unique=True)
	nome = models.CharField(max_length=128) # tem cadeiras com um nome tão grande?
	
	def __unicode__(self):
		return self.nome

class PostAvaliacao(forms.ModelForm):
	class Meta:
		model = Avaliacao
		exclude = ('aluno', 'resposta', 'karma')

class RegistroII(RegistrationForm):
	def clean_email(self):
		if self.cleaned_data['email'].split('@')[1] != "inf.ufrgs.br":
			raise forms.ValidationError("Apenas e-mails @inf.ufrgs.br são válidos.")
		return self.cleaned_data['email']